package interview.demo;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @Author tu zy
 * @Date 2020/12/4 13:41
 * @Version 1.0
 */
public class ThreadPoolDemo {
    public static void main(String[] args) {
        ExecutorService executorService = new ThreadPoolExecutor(3,10,10, TimeUnit.SECONDS,new LinkedBlockingQueue<>(64),(Runnable runnable)->{
            Thread thread = new Thread(runnable);
            thread.setName("back_up");
            return thread;
        });

        Future<?> future = executorService.submit(() -> {
            System.out.println("水到渠成");
        });
        Object o = null;
        try {
            o = future.get();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
        System.out.println(o);

    }
}
